package com.cc.moxingvoice.lock;

import android.content.Context;
import android.os.Bundle;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import com.cc.moxingvoice.base.BaseLock;
import com.cc.moxingvoice.constant.Connection;
import com.cc.moxingvoice.constant.MyUrl;
import com.cc.moxingvoice.databinding.ActivityWebBinding;
import com.cc.moxingvoice.databinding.FragmentForumBinding;
import com.cc.moxingvoice.response.GetUrlResponse;

import java.util.HashMap;

/**
 * 创建日期：2018/3/25 on 15:26
 * 描述：
 * 作者：郭士超
 * QQ：1169380200
 */

public class WebLock extends BaseLock<ActivityWebBinding> {

    public WebLock(Context context, ActivityWebBinding binding) {
        super(context, binding);
    }

    public WebLock(Context context, ActivityWebBinding binding, Bundle bundle) {
        super(context, binding, bundle);
    }

    @Override
    protected void init() {
        initWebView();
    }

    private void initWebView() {
        //WebView加载web资源
        mBinding.webView.loadUrl(mBundle.getString("url"));
        // 不让跳到浏览器中
        mBinding.webView.setWebViewClient(new WebViewClient(){
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                return false;// 返回false
            }
        });
        //启用支持Javascript
        WebSettings settings = mBinding.webView.getSettings();
        settings.setJavaScriptEnabled(true);
    }

    public boolean httpBack() {
        if (mBinding.webView.canGoBack()) {
            mBinding.webView.goBack();//返回上一页面
            return true;
        }
        return false;
    }

}
